/**
 * AdPersistenceServiceImpl.java 上午10:31:25 2012-5-2
 * Cyber Information Technology Co.,Ltd.
 *   
 *   http://www.citchina.cn
 *   citchina.org@gmail.com
 */
package cn.cit.wcif.ad.persistence.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import cn.cit.wcif.ad.api.IAd;
import cn.cit.wcif.ad.api.persistence.IAdEntity;
import cn.cit.wcif.ad.api.persistence.IAdPersistenceService;
import cn.cit.wcif.ad.persistence.jpa.entity.AdEntity;
import cn.cit.wcif.common.utils.DateUtil;

/**
 * @author Jonathan
 * @version 1.0
 * 
 */
@Repository
public class AdPersistenceServiceImpl implements IAdPersistenceService {
	@PersistenceContext
	private EntityManager em;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.ad.api.persistence.IAdPersistenceService#persistAd(cn.cit
	 * .wcif.ad.api.IAd)
	 */
	@Override
	public IAdEntity persistAd(IAd ad) {
		IAdEntity entity = new AdEntity();
		entity.setAdType(ad.getAdType());
		entity.setAdURL(ad.getAdURL());
		entity.setBackReason(ad.getBackReason());
		entity.setChID(ad.getChID());
		entity.setContent(ad.getContent());
		entity.setContentKey(ad.getContentKey());
		entity.setContentName(ad.getContentName());
		entity.setContentState(ad.getContentState());
		// entity.setId(ad.getId());
		entity.setLang(ad.getLang());
		entity.setPublishDate(DateUtil.parseToSQLDate(ad.getPublishDate(),
				DateUtil.yyMMddHHmmss));
		entity.setPublishUserID(ad.getPublishUserID());
		entity.setRecommend(ad.getRecommend());
		entity.setUpdateTime(DateUtil.parseToSQLDate(ad.getUpdateTime(),
				DateUtil.yyMMddHHmmss));
		entity.setUpdateUserID(ad.getUpdateUserID());
		em.persist(entity);
		return entity;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.ad.api.persistence.IAdPersistenceService#mergeAd(cn.cit.wcif
	 * .ad.api.IAd)
	 */
	@Override
	public IAdEntity mergeAd(IAd ad) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.ad.api.persistence.IAdPersistenceService#findAdByID(java.
	 * lang.String)
	 */
	@Override
	public IAdEntity findAdByID(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.cit.wcif.ad.api.persistence.IAdPersistenceService#findAdByLang(java
	 * .lang.String)
	 */
	@Override
	public List<IAdEntity> findAdByLang(String lang) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.cit.wcif.ad.api.persistence.IAdPersistenceService#pageAds(int,
	 * int)
	 */
	@Override
	public List<IAdEntity> pageAds(int pageSize, int perPage) {
		// TODO Auto-generated method stub
		return null;
	}

}
